package com.sumainfor.wx.system.maket.service;

import com.google.common.collect.Lists;
import com.sumainfor.common.ConstantsHousing;
import com.sumainfor.wx.system.maket.dao.RdTenantAskMapper;
import com.sumainfor.wx.system.maket.dao.RdWorderMapper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * <p>
 *
 * @author: zc
 * @create: 2019-08-27 14:06
 **/
@Service
public class RdTenantAskService implements Serializable {

    @Autowired
    RdTenantAskMapper rdTenantAskMapper;

    @Autowired
    RdWorderMapper rdWorderMapper;


    /**
     * 根据客户编号查询客户的接待记录
     * @param params
     * @return
     */
    public List<Map<String,Object>> getTenantAskListByTenId(Map<String,Object> params){
        List<Map<String,Object>> list=rdTenantAskMapper.getAskTimeByTenId(params);
        for ( Map<String, Object> map :list){
            System.out.println("时间:"+ map.get("AskTime"));

            List<Map<String,Object>> zczsList = rdTenantAskMapper.getTenantAskListByTenId(map);
            zczsList.stream().map(
                    item ->{
                        //处理查询房源特点
                        String inId = MapUtils.getString(item, "InId", "");
                        List<Object> trait = rdWorderMapper.selectDetailList(Lists.newArrayList(inId.split(",")))
                                .stream().map(tar -> tar.get("InName")).collect(Collectors.toList());
                        if (StringUtils.isNotBlank(MapUtils.getString(item, "Towards"))) {
                            trait.add("朝" + item.get("Towards"));
                        } else {
                            trait.add("朝" + MapUtils.getString(item, "Aspect"));
                            item.put("Towards", MapUtils.getString(item, "Aspect"));
                        }
                        item.remove("Aspect");
                        item.put("trait", trait);

                        item.remove("InId");



                        if(StringUtils.isNotBlank(MapUtils.getString(item,"ShowImg"))){
                            //处理图片
                            item.put("HouImg", item.get("ShowImg"));
                            item.remove("ShowImg");
                        }else{
                            item.put("HouImg", ConstantsHousing.DefaultHousingImg);
                        }


                        return item;
                    }).collect(Collectors.toList());


            map.put("TenantList",zczsList);
        }
        return list;
    }


}
